package com.qingke.exercise;

import java.io.File;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;

public class JaxbSample {

	public static void main(String[] args) {
		Student student = new Student();
		
		student.setId(999);
		student.setName("Alice");
		student.setGender("W");
		student.setAge(28);
		
		JAXBContext ctx;
		
		try {
			ctx =JAXBContext.newInstance(Student.class);
			ctx.createMarshaller().marshal(student,new File("student2.xml"));
			
			Object obj = ctx.createUnmarshaller().unmarshal(new File("student2.xml"));
			System.out.println(obj);
		} catch (JAXBException e) {
			e.printStackTrace();
		}
	}

}
